<template>
  <div>
    <a-form :form="form">
      <a-row>

        <a-col :xs="24" :sm="12">
          <a-form-item label="供料器尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['machineSize']" placeholder="请输入供料器尺寸"></a-input>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="封装类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['packageType']" placeholder="请输入封装类型"></a-input>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="标准上料角度" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['standardAngle']" placeholder="请输入标准上料角度"></a-input>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="喷码标准工时" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['sparyTime']" placeholder="请输入喷码标准工时"></a-input>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="管控类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['controlType']" placeholder="请输入管控类型"></a-input>
          </a-form-item>
        </a-col>
        <a-col :xs="24" :sm="12">
          <a-form-item label="老化时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <a-input v-decorator="['agingTime']" placeholder="请输入老化时间"></a-input>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </div>
</template>
<script>
  import pick from 'lodash.pick'
  import { getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'MesMaterielProduceForm',
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        validatorRules: {
        },
        confirmLoading: false,
      }
    },
    methods:{
      initFormData(url,id){
        this.clearFormData()
        if(!id){
          this.edit({})
        }else{
          getAction(url,{id:id}).then(res=>{
            if(res.success){
              let records = res.result
              if(records && records.length>0){
                this.edit(records[0])
              }
            }
          })
        }
      },
      edit(record){
        this.model = Object.assign({}, record)
        console.log("MesMaterielProduceForm-edit",this.model);
        let fieldval = pick(this.model,'machineSize','packageType','standardAngle','sparyTime','controlType','agingTime')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
      },
      getFormData(){
        let formdata_arr = []
        this.form.validateFields((err, values) => {
          if (!err) {
            let formdata = Object.assign(this.model, values)
            let isNullObj = true
            Object.keys(formdata).forEach(key=>{
              if(formdata[key]){
                isNullObj = false
              }
            })
            if(!isNullObj){
              formdata_arr.push(formdata)
            }
          }else{
            this.$emit("validateError","物料—生产表单校验未通过");
          }
        })
        console.log("物料—生产表单数据集",formdata_arr);
        return formdata_arr;
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'machineSize','packageType','standardAngle','sparyTime','controlType','agingTime'))
      },
      clearFormData(){
        this.form.resetFields()
        this.model={}
      }
    
    }
  }
</script>
